import rxAjax from '@/assets/js/ajax.js';


const Client={}
const Api = {
    sysTree:"/api-system/system/core/sysTree",
    sysTreeCat:"/api-system/system/core/sysTreeCat",
    SysAppManagerApi: '/api-system/system/core/sysAppManager',
    SysAppApi: '/api-system/system/core/sysApp',
}

function setStatistConfig(params, config){
    if(config && config!="undefined"){
        params.statisticConfig=config
    }
}

Api.getAllTopNodesByCatKey= function (catKey,readKey,isGrant,appIds,statisticConfig) {
    let params=
        {catKey:catKey,readKey:readKey,isGrant:isGrant,appIds:appIds};

    setStatistConfig(params,statisticConfig);

    return rxAjax.postForm(Api.sysTree + '/getAllTopNodesByCatKey',params)
}

Api.getTopByCatKey= function (catKey,readKey,isAdmin,isGrant,appId,statisticConfig,isBpmClient,isMyBpm) {
    let params=
        {catKey:catKey,readKey:readKey,isAdmin:isAdmin,isGrant:isGrant,appId:appId};
    if(isBpmClient){
        params.isBpmClient=isBpmClient;
    }
    if(isMyBpm){
        params.isMyBpm=isMyBpm;
    }
    setStatistConfig(params,statisticConfig);

    return rxAjax.postForm(Api.sysTree + '/getTopNodesByCatKey',params)
}



Api.getCatByParentId= function (parentId,catKey,readKey,isAdmin,isGrant,statisticConfig,isBpmClient,appId,isMyBpm) {

    let params={parentId:parentId,catKey:catKey,readKey:readKey,isAdmin:isAdmin,isGrant:isGrant};
    if(isBpmClient){
        params.isBpmClient=isBpmClient;
    }
    if(isMyBpm){
        params.isMyBpm=isMyBpm;
    }
    if(appId){
        params.appId=appId;
    }
    setStatistConfig(params,statisticConfig);

    return rxAjax.postForm(Api.sysTree + '/getByParentId',params)
}

Api.getByCatKey= function (catKey,readKey,isAdmin,isGrant,appId,statisticConfig) {
    let params={catKey:catKey,readKey:readKey,
        isAdmin:isAdmin,isGrant:isGrant,appId:appId};

    setStatistConfig(params,statisticConfig);

    return rxAjax.postForm(Api.sysTree + '/getByCatKey',params)
}

Api.getTreeCatByKey= function (catKey,isI18=true) {
    return rxAjax.get(Api.sysTreeCat + '/getTreeCatByKey?catKey='+catKey+'&isI18='+isI18)
}

/**
 * 获取当前用户的应用管理授权
 */
Api.getManagerOfCurUser =function() {
    var url= Api.SysAppManagerApi + '/getManagerOfCurUser' ;
    return rxAjax.get(url);
}

//获取我的代码所属应用
Api.getMyOwnBpmApp =function(params) {
    var url= Api.SysAppApi + '/getMyOwnBpmApp';
    return rxAjax.postJson(url,params);
}


//按分类和关键字检索二次开发的应用
Api.getMyOwnApp =function(params) {
    var url= Api.SysAppApi + '/getMyOwnApp';
    return rxAjax.postJson(url,params);
}

//按分类和关键字检索二次开发的应用
Api.getByCategoryOrKey =function(params) {
    var url= Api.SysAppApi + '/getByCategoryOrKey';
    return rxAjax.postUrl(url,params);
}

export default Api;
